﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Vehiculos

    Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar.Click

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese Dominio del vehículo a guardar.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If


        If (Len(Combomarca.Text) = 0) Then
            MsgBox("Ingrese Marca.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            Combomarca.Focus()
            Exit Sub
        End If

        If (Len(txttipo.Text) = 0) Then
            MsgBox("Ingrese Tipo.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txttipo.Focus()
            Exit Sub
        End If

        If (Len(txtmodelo.Text) = 0) Then
            MsgBox("Ingrese Modelo.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtmodelo.Focus()
            Exit Sub
        End If

        If (Len(txtmarcamotor.Text) = 0) Then
            MsgBox("Ingrese Marca de Motor.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtmarcamotor.Focus()
            Exit Sub
        End If

        If (Len(txtnummotor.Text) = 0) Then
            MsgBox("Ingrese Número de Motor.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtnummotor.Focus()
            Exit Sub
        End If

        If (Len(txtmarcachasis.Text) = 0) Then
            MsgBox("Ingrese Número de Chasis.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtmarcachasis.Focus()
            Exit Sub
        End If

        If (Len(txtnumchasis.Text) = 0) Then
            MsgBox("Ingrese Marca de Chasis.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtuso) = 0) Then
            MsgBox("Ingrese Uso del Vehículo.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If

        Dim oVehiculoNegocios As New Negocios.Nvehiculo
        Dim oVehiculo As New Entidades.Evehiculo
        oVehiculo.dominiovehiculo = UCase(txtdominio.Text)
        oVehiculo.marcavehiculo = UCase(Combomarca.Text)
        oVehiculo.tipovehiculo = UCase(txttipo.Text)
        oVehiculo.modelovehiculo = UCase(txtmodelo.Text)
        oVehiculo.marcamotor = UCase(txtmarcamotor.Text)
        oVehiculo.nummotor = UCase(txtnummotor.Text)
        oVehiculo.marcachasis = UCase(txtmarcachasis.Text)
        oVehiculo.numchasis = UCase(txtnumchasis.Text)
        oVehiculo.usovehiculo = UCase(txtuso.Text)

        Try
            If oVehiculoNegocios.guardarvehiculo(oVehiculo) Then
                MsgBox("Carga Exitosa de vehículo.", MsgBoxStyle.MsgBoxSetForeground, Title:="G.R.M SYSTEM")
            End If
        Catch ex As Exception
            MsgBox("Carga fallida. " + ex.Message, MsgBoxStyle.MsgBoxSetForeground, Title:="ERROR")
        End Try


    End Sub

    Private Sub Vehiculos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Combomarca.Items.Add("3-STAR")
        Combomarca.Items.Add("AGRALE")
        Combomarca.Items.Add("ALFA ROMEO")
        Combomarca.Items.Add("APPIA")
        Combomarca.Items.Add("ARO")
        Combomarca.Items.Add("ASIA")
        Combomarca.Items.Add("AUDI")
        Combomarca.Items.Add("BELAVTOMAZ")
        Combomarca.Items.Add("BLAC")
        Combomarca.Items.Add("BMW")
        Combomarca.Items.Add("CHERY")
        Combomarca.Items.Add("CHEVROLET")
        Combomarca.Items.Add("CHRYSLER")
        Combomarca.Items.Add("CITROEN")
        Combomarca.Items.Add("DACIA")
        Combomarca.Items.Add("DAEWOO")
        Combomarca.Items.Add("DAIHATSU")
        Combomarca.Items.Add("DEUTZ")
        Combomarca.Items.Add("DEUTZ AGRALE")
        Combomarca.Items.Add("DIMEX")
        Combomarca.Items.Add("DINA")
        Combomarca.Items.Add("DODGE")
        Combomarca.Items.Add("FERESA")
        Combomarca.Items.Add("FERRARI")
        Combomarca.Items.Add("FIAT")
        Combomarca.Items.Add("FIAT IVECO")
        Combomarca.Items.Add("FORD")
        Combomarca.Items.Add("GALLOPER")
        Combomarca.Items.Add("GAMMA")
        Combomarca.Items.Add("GAZ")
        Combomarca.Items.Add("GENERAL MOTORS")
        Combomarca.Items.Add("GMC")
        Combomarca.Items.Add("HEI BAO")
        Combomarca.Items.Add("HONDA")
        Combomarca.Items.Add("HYUNDAI")
        Combomarca.Items.Add("IES")
        Combomarca.Items.Add("INFINITI")
        Combomarca.Items.Add("INNOCENTI")
        Combomarca.Items.Add("INTERNACIONAL")
        Combomarca.Items.Add("ISUZU")
        Combomarca.Items.Add("IVECO")
        Combomarca.Items.Add("JAC")
        Combomarca.Items.Add("JAGUAR")
        Combomarca.Items.Add("JEEP")
        Combomarca.Items.Add("KAWASAKI")
        Combomarca.Items.Add("KIA")
        Combomarca.Items.Add("KYMCO")
        Combomarca.Items.Add("LADA")
        Combomarca.Items.Add("LANCER")
        Combomarca.Items.Add("LAND ROVER")
        Combomarca.Items.Add("LEXUS")
        Combomarca.Items.Add("MACK")
        Combomarca.Items.Add("MARCOPOLO")
        Combomarca.Items.Add("MARUTI")
        Combomarca.Items.Add("MARUTI SUZUKI")
        Combomarca.Items.Add("MASERATI")
        Combomarca.Items.Add("MAZDA")
        Combomarca.Items.Add("MERCEDES BENZ")
        Combomarca.Items.Add("MERCEDES BENZ/MARCOP")
        Combomarca.Items.Add("METRO")
        Combomarca.Items.Add("MG")
        Combomarca.Items.Add("MINI")
        Combomarca.Items.Add("MITSUBISHI")
        Combomarca.Items.Add("NAKAI")
        Combomarca.Items.Add("NISSAN")
        Combomarca.Items.Add("OPEL")
        Combomarca.Items.Add("PEUGEOT")
        Combomarca.Items.Add("PLYMOUTH")
        Combomarca.Items.Add("POLARIS")
        Combomarca.Items.Add("PORSCHE")
        Combomarca.Items.Add("PROTON")
        Combomarca.Items.Add("RANGE ROVER")
        Combomarca.Items.Add("RANQUEL")
        Combomarca.Items.Add("RENAULT")
        Combomarca.Items.Add("ROVER")
        Combomarca.Items.Add("SAAB")
        Combomarca.Items.Add("SAAB SCANIA")
        Combomarca.Items.Add("SANTANA")
        Combomarca.Items.Add("SANXING")
        Combomarca.Items.Add("SCANIA")
        Combomarca.Items.Add("SCANIA/MARCOPOLO")
        Combomarca.Items.Add("SEAT")
        Combomarca.Items.Add("SMART")
        Combomarca.Items.Add("SPACE")
        Combomarca.Items.Add("SSANGYONG")
        Combomarca.Items.Add("SUBARU")
        Combomarca.Items.Add("SUZUKI")
        Combomarca.Items.Add("SUZUKI - SANTANA")
        Combomarca.Items.Add("TATA")
        Combomarca.Items.Add("TOYOTA")
        Combomarca.Items.Add("VOLKSWAGEN")
        Combomarca.Items.Add("VOLVO")
        Combomarca.Items.Add("WULING")
        Combomarca.Items.Add("YUEJIN")

        
    End Sub

    Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
        Me.Close()
        Rodados.Show()
    End Sub

    Private Sub btnmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodificar.Click

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese Dominio.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If


        If (Len(Combomarca.Text) = 0) Then
            MsgBox("Ingrese Marca.", MsgBoxStyle.Exclamation, Title:="ERROR")
            Combomarca.Focus()
            Exit Sub
        End If

        If (Len(txttipo.Text) = 0) Then
            MsgBox("Ingrese Tipo.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txttipo.Focus()
            Exit Sub
        End If

        If (Len(txtmodelo.Text) = 0) Then
            MsgBox("Ingrese Modelo.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtmodelo.Focus()
            Exit Sub
        End If

        If (Len(txtmarcamotor.Text) = 0) Then
            MsgBox("Ingrese Marca de Motor.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtmarcamotor.Focus()
            Exit Sub
        End If

        If (Len(txtnummotor.Text) = 0) Then
            MsgBox("Ingrese Número de Motor.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtnummotor.Focus()
            Exit Sub
        End If

        If (Len(txtmarcachasis.Text) = 0) Then
            MsgBox("Ingrese Número de Chasis.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtmarcachasis.Focus()
            Exit Sub
        End If

        If (Len(txtnumchasis.Text) = 0) Then
            MsgBox("Ingrese Marca de Chasis.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtuso) = 0) Then
            MsgBox("Ingrese Uso del Vehículo.", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese el Dominio del Vehículo", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If
        Dim oVehiculoNegocios As New Negocios.Nvehiculo
        Dim oVehiculo As New Entidades.Evehiculo
        oVehiculo.dominiovehiculo = UCase(txtdominio.Text)
        oVehiculo.marcavehiculo = UCase(Combomarca.Text)
        oVehiculo.tipovehiculo = UCase(txttipo.Text)
        oVehiculo.modelovehiculo = UCase(txtmodelo.Text)
        oVehiculo.marcamotor = UCase(txtmarcamotor.Text)
        oVehiculo.nummotor = UCase(txtnummotor.Text)
        oVehiculo.numchasis = UCase(txtnumchasis.Text)
        oVehiculo.marcachasis = UCase(txtmarcachasis.Text)
        oVehiculo.usovehiculo = UCase(txtuso.Text)
        Try
            If oVehiculoNegocios.modificarvehiculo(oVehiculo) Then
                MsgBox("Modificación Exitosa de Vehículo.", MsgBoxStyle.MsgBoxSetForeground, Title:="G.R.M SYSTEM")
            End If

        Catch ex As Exception
            MsgBox("Carga fallida." + ex.Message, MsgBoxStyle.MsgBoxSetForeground, Title:="ERROR")
        End Try

    End Sub

    Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese el Dominio del Vehículo", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtdominio.Focus()
            Exit Sub
        End If

        Dim oVehiculoNegocios As New Negocios.Nvehiculo
        Dim oVehiculo As New Entidades.Evehiculo
        oVehiculo.dominiovehiculo = UCase(txtdominio.Text)

        Try

            Dim resp As Integer

            resp = MsgBox("¿Desea eliminar los datos?", MsgBoxStyle.YesNo)
            If resp = 6 Then
                oVehiculoNegocios.eliminarvehiculo(oVehiculo)
                MsgBox("El Vehículo se eliminó correctamente.", MsgBoxStyle.MsgBoxSetForeground, Title:="G.R.M SYSTEM")
            End If
        Catch ex As Exception
            MsgBox("El vehículo no se pudo eliminar." + ex.Message, MsgBoxStyle.MsgBoxSetForeground, Title:="ERROR")
        End Try
    End Sub


    Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click

        If (Len(txtbusqueda.Text) = 0) Then
            MsgBox("Ingrese el Dominio del Vehículo a buscar", MsgBoxStyle.Exclamation, Title:="ERROR")
            txtbusqueda.Focus()
            Exit Sub
        End If

        Dim oVehiculoNegocios As New Negocios.Nvehiculo
        Dim oVehiculo As New Entidades.Evehiculo
        oVehiculo.dominiovehiculo = UCase(txtbusqueda.Text)
        gvvehiculo.DataSource = oVehiculoNegocios.buscarvehiculos(txtbusqueda.Text)
        txtbusqueda.Text = ""
    End Sub

    Private Sub btnblanquear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnblanquear.Click
        Dim oVehiculoNegocios As New Negocios.Nvehiculo
        Dim oVehiculo As New Entidades.Evehiculo
        txtdominio.Text = ""
        Combomarca.Text = ""
        txttipo.Text = ""
        txtdominio.Text = ""
        txtmarcamotor.Text = ""
        txtnummotor.Text = ""
        txtmarcachasis.Text = ""
        txtnumchasis.Text = ""
        txtuso.Text = ""
        txtdominio.Focus()
    End Sub

   
End Class